function gui.float:select(choice)
  if gui.float[choice] then
    gui.float.selected = choice
    gui.float.current = gui.float[choice]
  end
end

-- button time
--[[ example

  gui.button.add({
    id = "",
    text = "click!",
    image = nil,
    size = {100,100},
    pos = {0,0},
    release = function() 
      --do click stuff 
    end
  })

________________________________
--------------------------------
8******************************8
    other options:

    press,hoverOn,hoverOff = func
    held, hovered, fill = bool

8******************************8
--------------------------------

  })

]]

function gui.button.add(button)

  --overwrite values not set with defaults
  for k,v in pairs(gui.buttonDefaults) do
    if not button[k] then  
      button[k] = v
    end
  end

  table.insert(gui.button.buttons, button)
  table.insert(gui.float.current.grid, XYWH(button))
  return button
end

function XYWH(guiElement)
  -- all guiElements being passed through here SHOULD be the same.  If not... what the fuck for DAYS.
  return {guiElement.pos[1], guiElement.pos[2], guiElement.size[1], guiElement.size[2]}
end

-- Gets the actual button table
-- ex:
-- if gui.button.get("myButton").hovered then 
--    doEffects() 
-- end

function gui.button.get(id)
  return table.hasValue(gui.button.buttons, id)
end

-- these just hook into the normal update and draw codes to keep it clean
function gui.draw()
  local lg = love.graphics

  for k,v in pairs(gui.button.buttons) do
    local c = v.colorUp
    
    if v.hovered then
      c = v.colorHover
    end

    if v.held then
      c = v.colorDown
    end

    lg.setColor(c[1], c[2], c[3], c[4])

    x = v.pos[1]
    y = v.pos[2]
    w = v.size[1]
    h = v.size[2]

    if not v.cover then
      for _=0, 10, 2 do
      v.cover = love.graphics.newSpriteBatch
      v.cover:setImage(iDB.UI.button)
      v.cover:addq
      
      end
    end


  lg.rectangle("fill", x, y, w, h)
  end

  --steadyDebug 
  if debugString then
    lg.setColor(200,200,200,255)
    lg.print(debugString, 5, 5)
    lg.setColor(40,40,40,255)
    lg.print(debugString, 5, 15)
  end
end

hook.Add("draw", "drawGUI", gui.draw)

function gui.update(dt)

  -- update the selected float
  gui.float[gui.float.selected] = gui.float.current

  -- check 'mouse collisions'
  for k,v in pairs(gui.button.buttons) do
    
    if mouseIsTouching({v.pos[1], v.pos[2], v.size[1], v.size[2]}) then
      
      if not v.hovered then 
        tryCall(v.hoverOn)
        v.hovered=true
      end

      if love.mouse.isDown( "l" ) then
        if not v.held and v.hovered then 
          tryCall(v.press)
          v.held=true
        end
      else
        if v.held then
          tryCall(v.release)
          v.held=false
        end
      end

    else

      if v.hovered then 
        tryCall(v.hoverOff)
        v.hovered=false
      end

      if v.held then
        tryCall(v.release)
        v.held=false
      end

    end

  end

end

hook.Add("think", "thinkGUI", gui.update)